﻿' TRIGSOFT IS A TRIGONOMETRY BASED SOFTWARE THAT FOCUSES MAINLY ON THREE RULES: AREA RULE : SINE RULE : COSINE RULE
'@Author: Dipolelo
'Interface: Graphical
'Date: 27/11/2011

Imports Microsoft.VisualBasic.VBMath
Imports System.Math
Imports System.Deployment.Application
Imports System.IO

Public Class Main

    Dim chars As String = "<,>.';:|\}]{[+=)(&^%$#@!~`/"
    Dim Ans As Decimal

    Private Sub AreaRadio_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles AreaRadio.CheckedChanged
        PictureBox1.Load("Trigsoft_Previews\AreaRule.png")
        Form3.Visible = False
        NumericUpDown2.Visible = False
        Label6.Text = "Area:"
        Label4.Text = "Sin<X>"

        If (SideXBox.TextLength > 0 Or SideYBox.TextLength > 0 Or NumericUpDown1.Value > 20.0 And Not System.IO.File.Exists("c:\Program Files\Trigsoft\Trigbase\Subjects.bat")) Then
            ClearNote.Show()

            ' Default values when chaing subject
            Me.SideYBox.Clear()
            Me.SideXBox.Clear()
            Me.AreaBox.Clear()
            Me.NumericUpDown1.Value = 20.0
            Me.NumericUpDown2.Value = 20.0
            Me.AnswerBox.Clear()
            Me.ComboBox1.Text = "      --Start Here--"
            Status.Text = "Ready"
            Me.SideXBox.Enabled = False
            Me.SideYBox.Enabled = False
            Me.AreaBox.Enabled = False
            Me.NumericUpDown1.Enabled = False
            Me.NumericUpDown2.Enabled = False



            If (AreaRadio.Checked And Not ComboBox1.Items.Contains("Area")) Then
                ComboBox1.Items.Add("Area")
                ComboBox1.Items.Remove("AngleY")
                ComboBox1.Items.Remove("SideZ")
            End If

        ElseIf (System.IO.File.Exists("c:\Program Files\Trigsoft\Trigbase\Subjects.bat")) Then

            ' Default values when chaing subject
            Me.SideYBox.Clear()
            Me.SideXBox.Clear()
            Me.AreaBox.Clear()
            Me.NumericUpDown1.Value = 20.0
            Me.NumericUpDown2.Value = 20.0
            Me.AnswerBox.Clear()
            Me.ComboBox1.Text = "      --Start Here--"
            Status.Text = "Ready"
            Me.SideXBox.Enabled = False
            Me.SideYBox.Enabled = False
            Me.AreaBox.Enabled = False
            Me.NumericUpDown1.Enabled = False
            Me.NumericUpDown2.Enabled = False

            If (AreaRadio.Checked And Not ComboBox1.Items.Contains("Area")) Then
                ComboBox1.Items.Add("Area")
                ComboBox1.Items.Remove("AngleY")
                ComboBox1.Items.Remove("SideZ")
            End If
        Else
            If (AreaRadio.Checked And Not ComboBox1.Items.Contains("Area")) Then
                ComboBox1.Items.Add("Area")
                ComboBox1.Items.Remove("AngleY")
                ComboBox1.Items.Remove("SideZ")
            End If
        End If
    End Sub

    Private Sub SineRadio_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SineRadio.CheckedChanged
        PictureBox1.Load("Trigsoft_Previews\SineRule.png")
        ComboBox1.Items.Remove("Area")
        Label6.Text = "Sin<A>"
        Label4.Text = "Sin<B>"



        If (SideXBox.TextLength > 0 Or SideYBox.TextLength > 0 Or NumericUpDown1.Value > 20.0 And Not System.IO.File.Exists("c:\Program Files\Trigsoft\Trigbase\Subjects.bat")) Then
            ClearNote.Show()


            ' Default values when chaing subject
            Me.SideYBox.Clear()
            Me.SideXBox.Clear()
            Me.AreaBox.Clear()
            Me.NumericUpDown1.Value = 20.0
            Me.NumericUpDown2.Value = 20.0
            Me.AnswerBox.Clear()
            Me.ComboBox1.Text = "      --Start Here--"
            Status.Text = "Ready"
            Me.SideXBox.Enabled = False
            Me.SideYBox.Enabled = False
            Me.AreaBox.Enabled = False
            Me.NumericUpDown1.Enabled = False
            Me.NumericUpDown2.Enabled = False

            If (SineRadio.Checked And Not ComboBox1.Items.Contains("AngleY")) Then
                ComboBox1.Items.Add("AngleY")
                ComboBox1.Items.Remove("SideZ")
            End If

        ElseIf (System.IO.File.Exists("c:\Program Files\Trigsoft\Trigbase\Subjects.bat")) Then

            ' Default values when chaing subject
            Me.SideYBox.Clear()
            Me.SideXBox.Clear()
            Me.AreaBox.Clear()
            Me.NumericUpDown1.Value = 20.0
            Me.NumericUpDown2.Value = 20.0
            Me.AnswerBox.Clear()
            Me.ComboBox1.Text = "      --Start Here--"
            Status.Text = "Ready"
            Me.SideXBox.Enabled = False
            Me.SideYBox.Enabled = False
            Me.AreaBox.Enabled = False
            Me.NumericUpDown1.Enabled = False
            Me.NumericUpDown2.Enabled = False

            If (SineRadio.Checked And Not ComboBox1.Items.Contains("AngleY")) Then
                ComboBox1.Items.Add("AngleY")
                ComboBox1.Items.Remove("SideZ")
            End If
        Else
            If (SineRadio.Checked And Not ComboBox1.Items.Contains("AngleY")) Then
                ComboBox1.Items.Add("AngleY")
                ComboBox1.Items.Remove("SideZ")
            End If
        End If
    End Sub

    Private Sub CosineRadio_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CosineRadio.CheckedChanged
        PictureBox1.Load("Trigsoft_Previews\CosineRule.png")
        Form3.Visible = False
        NumericUpDown2.Visible = False
        ComboBox1.Items.Remove("AngleY")
        ComboBox1.Items.Remove("Area")
        Label6.Text = "SideZ:"
        Label4.Text = "Cos<X>"


        If (SideXBox.TextLength > 0 Or SideYBox.TextLength > 0 Or NumericUpDown1.Value > 20.0 And Not System.IO.File.Exists("c:\Program Files\Trigsoft\Trigbase\Subjects.bat")) Then
            ClearNote.Show()

            ' Default values when chaing subject
            Me.SideYBox.Clear()
            Me.SideXBox.Clear()
            Me.AreaBox.Clear()
            Me.NumericUpDown1.Value = 20.0
            Me.NumericUpDown2.Value = 20.0
            Me.AnswerBox.Clear()
            Me.ComboBox1.Text = "      --Start Here--"
            Status.Text = "Ready"
            Me.SideXBox.Enabled = False
            Me.SideYBox.Enabled = False
            Me.AreaBox.Enabled = False
            Me.NumericUpDown1.Enabled = False
            Me.NumericUpDown2.Enabled = False

            If (CosineRadio.Checked And Not ComboBox1.Items.Contains("SideZ")) Then
                ComboBox1.Items.Remove("AngleX")
                ComboBox1.Items.Add("SideZ")
                ComboBox1.Items.Add("AngleX")
            End If

        ElseIf (System.IO.File.Exists("c:\Program Files\Trigsoft\Trigbase\Subjects.bat")) Then

            ' Default values when chaing subject
            Me.SideYBox.Clear()
            Me.SideXBox.Clear()
            Me.AreaBox.Clear()
            Me.NumericUpDown1.Value = 20.0
            Me.NumericUpDown2.Value = 20.0
            Me.AnswerBox.Clear()
            Me.ComboBox1.Text = "      --Start Here--"
            Status.Text = "Ready"
            Me.SideXBox.Enabled = False
            Me.SideYBox.Enabled = False
            Me.AreaBox.Enabled = False
            Me.NumericUpDown1.Enabled = False
            Me.NumericUpDown2.Enabled = False

            If (CosineRadio.Checked And Not ComboBox1.Items.Contains("SideZ")) Then
                ComboBox1.Items.Remove("AngleX")
                ComboBox1.Items.Add("SideZ")
                ComboBox1.Items.Add("AngleX")
            End If
        Else
            If (CosineRadio.Checked And Not ComboBox1.Items.Contains("SideZ")) Then
                ComboBox1.Items.Remove("AngleX")
                ComboBox1.Items.Add("SideZ")
                ComboBox1.Items.Add("AngleX")
            End If
        End If
    End Sub

    Private Sub ExitToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ExitToolStripMenuItem.Click
        Dim Path As String = "c:/Program Files/Trigsoft/Trigbase/Trigsoft.bat"

        If (File.Exists(Path)) Then
            End
        Else
            SPECIALTHANKS.Show()
        End If
    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click

        Dim Path As String = "c:\Program Files\Trigsoft\Trigbase\Trigsoft_EXIT"

        If (File.Exists(Path)) Then
            End
        ElseIf (Not File.Exists(Path)) Then
            SPECIALTHANKS.Show()
        End If
    End Sub

    Private Sub PreviewsToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PreviewsToolStripMenuItem.Click
        Previews.Show()
    End Sub

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

        For I As Integer = 0 To 100000
            SplashScreen1.Show()
            If (I = 100000) Then
                SplashScreen1.Hide()
                Me.Opacity = 100.0
            End If
        Next I

        Previews.RadioButton1.Select()
        AreaRadio.Select()
        ComboBox1.Focus()
        NumericUpDown2.Visible = False

    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Go.Click

        If (Me.ComboBox1.SelectedItem = Nothing) Then
            MessageBox.Show("Please select subject formular in the Solving menu.", "Notification", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
        ElseIf (ComboBox1.SelectedItem.Equals("SideX") And AreaRadio.Checked) Then

            SideX_Area()

        ElseIf (ComboBox1.SelectedItem = "SideY" And AreaRadio.Checked) Then

            SideY_Area()

        ElseIf (ComboBox1.SelectedItem = "AngleX" And AreaRadio.Checked) Then

            Label9.Text = " "

            If (Fixer.Value > 0) Then
                ErrorProvider1.SetError(Fixer, "An angle does not have decimals.")
            Else
                ErrorProvider1.Clear()
            End If

            Angle_Area()

        ElseIf (ComboBox1.SelectedItem = "Area" And AreaRadio.Checked) Then

            Area_Area()

        ElseIf (ComboBox1.SelectedItem = "SideX" And SineRadio.Checked) Then

            SideX_Sine()

        ElseIf (SineRadio.Checked And ComboBox1.SelectedItem = "SideY") Then

            SideY_Sine()

        ElseIf (ComboBox1.SelectedItem = "AngleX" And SineRadio.Checked) Then

            Label9.Text = " "

            If (Fixer.Value > 0) Then
                ErrorProvider1.SetError(Fixer, "An angle does not have decimals.")
            Else
                ErrorProvider1.Clear()
            End If

            AngleX_Sine()

        ElseIf (ComboBox1.SelectedItem = "AngleY" And SineRadio.Checked) Then

            Label9.Text = " "

            If (Fixer.Value > 0) Then
                ErrorProvider1.SetError(Fixer, "An angle does not have decimals.")
            Else
                ErrorProvider1.Clear()
            End If

            AngleY_Sine()

        ElseIf (ComboBox1.SelectedItem = "SideX" And CosineRadio.Checked) Then

            SideX_Cosine()

        ElseIf (ComboBox1.SelectedItem = "SideY" And CosineRadio.Checked) Then

            SideY_Cosine()

        ElseIf (ComboBox1.SelectedItem = "SideZ" And CosineRadio.Checked) Then

            SideZ_Cosine()

        ElseIf (ComboBox1.SelectedItem = "AngleX" And CosineRadio.Checked) Then

            Label9.Text = " "

            If (Fixer.Value > 0) Then
                ErrorProvider1.SetError(Fixer, "Angles do not have decimals.")
            Else
                ErrorProvider1.Clear()
            End If

            Angle_Cosine()

        End If
    End Sub

    Public Sub SideX_Cosine()
        Dim b As Integer
        Dim c As Integer



        If (IsLetters(SideYBox.Text) Or IsLetters(AreaBox.Text)) Then
            ErrorProvider1.SetError(NumericUpDown1, "Invalid Input.")
        Else
            b = CInt(SideYBox.Text)
            c = CInt(AreaBox.Text)
        End If

        Dim AddSquare As Integer = (b ^ 2) + (c ^ 2)
        Dim Ba As Integer = b ^ 2
        Dim Ca As Integer = c ^ 2
        Dim NEG As Integer = (2 * (b * c))
        Dim ee As Decimal = ToRadians(NumericUpDown1.Value)


        Ans = Math.Sqrt(AddSquare - NEG * Math.Cos(ee))
        AnswerBox.Text = Ans & " cm"
        Label9.Text = "NOTE: You can tune the decimals of your answer" & vbCrLf & "using the control labeled Decimals then, Click Calculate again."
    End Sub

    Public Sub SideY_Cosine()
        Dim b As Integer
        Dim c As Integer
        Dim Letter As Char = "a"c


        If (SideXBox.Text.Contains(Letter)) Then
            Go.Enabled = False
            Status.Text = "Text found in SideX box. Use numeric values only."
        Else
            Status.Text = "Enter values"
            Go.Enabled = True
        End If

        If (SideXBox.Text.Contains("a"c) Or SideXBox.Text.Contains("b"c) Or SideXBox.Text.Contains("c"c) Or SideXBox.Text.Contains("d"c) Or SideXBox.Text.Contains("e"c) Or SideXBox.Text.Contains("f"c) Or SideXBox.Text.Contains("g"c) Or SideXBox.Text.Contains("h"c) Or SideXBox.Text.Contains("i"c) Or SideXBox.Text.Contains("j"c) Or SideXBox.Text.Contains("k"c) Or SideXBox.Text.Contains("l"c) Or SideXBox.Text.Contains("m"c) Or SideXBox.Text.Contains("n"c) Or SideXBox.Text.Contains("o"c) Or SideXBox.Text.Contains("p"c) Or SideXBox.Text.Contains("q"c) Or SideXBox.Text.Contains("r"c) Or SideXBox.Text.Contains("s"c) Or SideXBox.Text.Contains("t"c) Or SideXBox.Text.Contains("u"c) Or SideXBox.Text.Contains("v"c) Or SideXBox.Text.Contains("w"c) Or SideXBox.Text.Contains("x"c) Or SideXBox.Text.Contains("y"c) Or SideXBox.Text.Contains("z"c)) Then 'IsLetters(SideXBox.Text) Or IsLetters(AreaBox.Text)) Then
            Status.Text = "Letters found."
        Else
            b = CInt(SideXBox.Text)
            c = CInt(AreaBox.Text)

            Dim AddSquare As Integer = (b ^ 2) + (c ^ 2)
            Dim Ba As Integer = b ^ 2
            Dim Ca As Integer = c ^ 2
            Dim NEG As Integer = (2 * (b * c))
            Dim ee As Decimal = ToRadians(NumericUpDown1.Value)


            Ans = Math.Sqrt(AddSquare - NEG * Math.Cos(ee))
            AnswerBox.Text = Ans & " cm"
            Label9.Text = "NOTE: You can tune the decimals of your answer" & vbCrLf & "using the control labeled Decimals then, Click Calculate again."
        End If
    End Sub

    Public Sub SideZ_Cosine()
        Dim b As Integer
        Dim c As Integer



        If (IsLetters(SideXBox.Text) Or IsLetters(SideYBox.Text)) Then
            ErrorProvider1.SetError(NumericUpDown1, "Invalid Input.")
        Else
            b = CInt(SideYBox.Text)
            c = CInt(SideXBox.Text)
        End If

        Dim AddSquare As Integer = (b ^ 2) + (c ^ 2)
        Dim Ba As Integer = b ^ 2
        Dim Ca As Integer = c ^ 2
        Dim NEG As Integer = (2 * (b * c))
        Dim ee As Decimal = ToRadians(NumericUpDown1.Value)


        Ans = Math.Sqrt(AddSquare - NEG * Math.Cos(ee))
        AnswerBox.Text = Ans & " cm"
        Label9.Text = "NOTE: You can tune the decimals of your answer" & vbCrLf & "using the control labeled Decimals then, Click Calculate again."
    End Sub

    Public Sub Angle_Cosine()

        Dim root As Decimal
        Dim a As Integer
        Dim b As Integer
        Dim c As Integer
        Dim rootTwo As Decimal
        Dim Add As Decimal


        If (IsLetters(SideXBox.Text) Or IsLetters(AreaBox.Text) Or IsLetters(AreaBox.Text)) Then
            ErrorProvider1.SetError(NumericUpDown1, "Invalid Input.")
        Else
            a = CInt(SideXBox.Text)
            b = CInt(SideYBox.Text)
            c = CInt(AreaBox.Text)
        End If

        '------------------------------------Calculations-----------------------------------------

        Dim intB As Decimal
        Dim intC As Decimal
        Dim inverse As Decimal
        Dim rootedB As Integer
        Dim rootedC As Integer
        Dim rootedA As Integer

        intC = c
        intB = b

        rootedA = a ^ 2
        rootedB = b ^ 2
        rootedC = c ^ 2
        ' Cosine rule has form -> a^2 = b2 + c2 - 2bc*sinA
        Add = rootedB + rootedC
        root = rootedA - Add

        ' If root is less than zero devide root by -1.
        If (root < 0) Then
            root = root / -1
            rootTwo = (2 * (intB * intC))
            inverse = root / rootTwo
            AnswerBox.Text = Math.Round(Math.Acos(inverse) * 180 / PI, 0) & " degrees"
        Else

            rootTwo = 2 * (intC * intB)
            inverse = root / rootTwo
            AnswerBox.Text = Math.Round(Math.Acos(inverse) * 180 / PI, 0) & " degrees"
        End If

    End Sub

    Public Sub AngleX_Sine()

        Dim bSinA As Decimal
        Dim b As Decimal
        Dim a As Decimal
        Dim proQuotient As Decimal

        If (SideXBox.TextLength = 0 Or SideYBox.TextLength = 0) Then
            MessageBox.Show("Please enter your values in the box.", "Notification", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
        Else
            b = CInt(SideXBox.Text)
            a = CInt(SideYBox.Text)
        End If

        '----------------------------------------Calculations------------------------------------
        bSinA = b * Math.Sin(ToRadians(NumericUpDown2.Value))
        proQuotient = bSinA / a
        Ans = Math.Round(ToDegrees(Math.Asin(proQuotient)), 0)
        '----------------------------------------------------------------------------------------

        If (Ans < 0) Then
            Ans = Ans / -1
            Label9.Text = "NOTE: You can tune the decimals of your answer" & vbCrLf & "using the control labeled Decimals in Configuration window then Click Save Settings; Click Calculate again."
            AnswerBox.Text = Ans & " degrees"
        Else
            Label9.Text = "NOTE: You can tune the decimals of your answer" & vbCrLf & "using the control labeled Decimals in Configuration window then Click Save Settings; Click Calculate again."
            AnswerBox.Text = Ans & " degrees"
        End If

    End Sub

    Public Sub AngleY_Sine()

        Dim bSinA As Decimal
        Dim a As Decimal
        Dim b As Decimal
        Dim proQuotient As Decimal

        If (IsLetters(SideXBox.Text)) Then
            MessageBox.Show("Please enter your values in the box.", "Notification", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
        Else
            a = CInt(SideXBox.Text)
            b = CInt(SideYBox.Text)
        End If

        '----------------------------------------Calculations--------------------------------
        bSinA = b * Math.Sin(ToRadians(NumericUpDown2.Value))
        proQuotient = bSinA / a

        If (proQuotient >= 1) Then
            AnswerBox.Text = "Invalid number."
        Else
            AnswerBox.Text = Math.Round(ToDegrees(Math.Asin(proQuotient)), CInt(Form3.DecimalsUpDown.Value)) & " degrees"
        End If
        '------------------------------------------------------------------------------------
    End Sub

    Public Sub SideX_Sine()
        Dim aSinB As Decimal
        Dim a As Decimal
        Dim proQuotient As Decimal

        If (IsLetters(SideYBox.Text)) Then
            ErrorProvider1.SetError(NumericUpDown1, "Invalid Input.")
        Else
            a = CDec(SideYBox.Text)
        End If

        '--------------------------------------Calculations----------------------------------------------------------
        aSinB = Math.Sin(ToRadians(NumericUpDown2.Value)) * a
        proQuotient = Math.Round(aSinB / Math.Sin(ToRadians(NumericUpDown1.Value)), CInt(Form3.DecimalsUpDown.Value))
        Ans = proQuotient
        '------------------------------------------------------------------------------------------------------------
        If (Ans < 0) Then
            Ans = Ans / -1
            Label9.Text = "NOTE: You can tune the decimals of your answer" & vbCrLf & "using the control labeled Decimals in Configuration window then, Click Save Settings; Click Calculate again."
            AnswerBox.Text = Ans & " cm"
        Else
            Label9.Text = "NOTE: You can tune the decimals of your answer" & vbCrLf & "using the control labeled Decimals in Configuration window then, Click Save Settings; Click Calculate again."
            AnswerBox.Text = Ans & " cm"
        End If


    End Sub

    Public Sub SideY_Sine()

        Dim bSineA As Decimal
        Dim b As Decimal

        If (IsLetters(SideXBox.Text) Or IsLetters(AreaBox.Text)) Then
            MessageBox.Show("Please enter your values in the box.", "Notification", MessageBoxButtons.OK, MessageBoxIcon.Hand)
        Else
            b = CDec(SideXBox.Text)
        End If

        '--------------------------Calculations----------------------------------------------------------------------
        bSineA = Math.Sin(ToRadians(NumericUpDown1.Value)) * b
        Ans = Math.Round(bSineA / Math.Sin(ToRadians(NumericUpDown2.Value)), CInt(Form3.DecimalsUpDown.Value))
        '------------------------------------------------------------------------------------------------------------


        If (Ans < 0) Then
            Ans = Ans / -1
            Label9.Text = "NOTE: You can tune the decimals of your answer" & vbCrLf & "using the control labeled Decimals in Configuration window then, Click Save Settings; Click Calculate again."
            AnswerBox.Text = Ans & " cm"
        Else
            Label9.Text = "NOTE: You can tune the decimals of your answer" & vbCrLf & "using the control labeled Decimals in Configuration window then, Click Save Settings; Click Calculate again."
            AnswerBox.Text = Ans & " cm"
        End If
    End Sub

    Public Sub SideY_Area()
        Dim Xbox As Decimal
        Dim Area As Decimal
        Dim Prod As Decimal

        If (IsLetters(SideXBox.Text) Or IsLetters(AreaBox.Text)) Then
            ErrorProvider1.SetError(NumericUpDown1, "Invalid Input.")
        Else
            Xbox = CInt(SideXBox.Text)
            Area = CInt(AreaBox.Text)
        End If


        '---------------------------Calculations---------------------
        Prod = Math.Sin(ToRadians(NumericUpDown1.Value)) * Xbox
        Ans = Math.Round(Area / Prod, CInt(Fixer.Value))
        '------------------------------------------------------------

        If (Ans < 0) Then
            Ans = Ans / -1
            Label9.Text = "NOTE: You can tune the decimals of your answer" & vbCrLf & "using the control labeled Decimals then, Click Calculate again."
            AnswerBox.Text = Ans & " cm"
        Else
            Label9.Text = "NOTE: You can tune the decimals of your answer" & vbCrLf & "using the control labeled Decimals then, Click Calculate again."
            AnswerBox.Text = Ans & " cm"
        End If
    End Sub
    'Function that converts from Radians To Degrees.
    'Returns a degree of a specified x value.
    Private Function ToDegrees(ByVal x) As Decimal
        Return x * 180.0 / Math.PI
    End Function
    'Function that converts from Degrees To Radians.
    'Returns a Radian of a specified n value.
    REM
    Shared Function ToRadians(ByVal n) As Decimal
        Return Math.PI * n / 180.0
    End Function

    Private Function IsLetters(ByVal Control As Char)
        Return Control >= "a"c And Control <= "z"c
    End Function

    Public Sub Angle_Area()
        Dim Ybox As Integer
        Dim Xbox As Integer
        Dim Area As Decimal
        Dim Inverse As Decimal
        Dim Prod As Integer

        If (IsLetters(SideXBox.Text) Or IsLetters(SideYBox.Text) Or IsLetters(AreaBox.Text)) Then
            ErrorProvider1.SetError(NumericUpDown1, "Invalid Input.")
        Else
            Ybox = CInt(SideYBox.Text)
            Xbox = CInt(SideXBox.Text)
            Area = CInt(AreaBox.Text)
        End If

        '------------------------------Calculations---------------------------------------
        Prod = Ybox * Xbox
        Inverse = Area / Prod

        If (Inverse > 1) Then
            AnswerBox.Text = "Invalid number."
        Else
            AnswerBox.Text = Math.Round(Math.Asin(Inverse) * 180 / PI, 1) & " degrees"
        End If
        '---------------------------------------------------------------------------------
    End Sub

    Sub SideX_Area()

        Dim pro As Decimal
        Dim Ybox As Integer
        Dim AreaBox1 As Decimal

        If (IsLetters(SideYBox.Text) Or IsLetters(AreaBox.Text)) Then
            ErrorProvider1.SetError(NumericUpDown1, "Invalid Input.")
        Else
            Ybox = Integer.Parse(SideYBox.Text)
            AreaBox1 = CInt(AreaBox.Text)

            ErrorProvider1.Clear()
            '------------------------Calculations------------------
            pro = Math.Sin(ToRadians(NumericUpDown1.Value)) * Ybox
            Ans = Math.Round(AreaBox1 / pro, CInt(Fixer.Value))
            '------------------------------------------------------
            If (Ans < 0) Then
                Ans = Ans / -1
                AnswerBox.Text = Math.Round(Ans, CInt(Fixer.Value)) & " cm"
                Label9.Text = "NOTE: You can tune the decimals of your answer" & vbCrLf & "using the control labeled Decimals then, Click Calculate again."
            Else
                AnswerBox.Text = Math.Round(Ans, CInt(Fixer.Value)) & " cm"
                Label9.Text = "NOTE: You can tune the decimals of your answer" & vbCrLf & "using the control labeled Decimals then, Click Calculate again."
            End If
        End If
    End Sub

    Public Sub Area_Area()

        Dim Product As Decimal
        Dim Ybox As Decimal
        Dim Xbox As Decimal
        Dim Angle As Decimal

        If (IsLetters(SideXBox.Text) Or IsLetters(SideYBox.Text)) Then
            ErrorProvider1.SetError(NumericUpDown1, "Invalid Input.")
        Else
            Xbox = CInt(SideXBox.Text)
            Ybox = CInt(SideYBox.Text)
            Angle = CInt(NumericUpDown1.Value)
        End If

        '--------------------------------------Calculations---------------------------------------
        Product = Ybox * Xbox
        Angle = Math.Round(Product * Math.Sin(ToRadians(NumericUpDown1.Value)), CInt(Fixer.Value))
        '-----------------------------------------------------------------------------------------

        If (Angle < 0) Then
            Angle = Angle / -1
            Label9.Text = "NOTE: You can tune the decimals of your answer" & vbCrLf & "using the control labeled Decimals then, Click Calculate again."
            AnswerBox.Text = Angle & " mm^3"
        Else
            Label9.Text = "NOTE: You can tune the decimals of your answer" & vbCrLf & "using the control labeled Decimals then, Click Calculate again."
            AnswerBox.Text = Angle & " mm^3"
        End If

    End Sub

    Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click

        If (AreaRadio.Checked And ComboBox1.SelectedItem = "SideX") Then
            SideXBox.Clear()
            AnswerBox.Clear()
            AreaBox.Enabled = True
            NumericUpDown1.Enabled = True
            NumericUpDown1.Minimum = 20
            SideXBox.Enabled = False
            SideYBox.Enabled = True
            Clear.Enabled = True
            SideYBox.Focus()
        ElseIf (AreaRadio.Checked And ComboBox1.SelectedItem = "SideY") Then
            SideXBox.Clear()
            AnswerBox.Clear()
            SideYBox.Enabled = False
            AreaBox.Enabled = True
            NumericUpDown1.Minimum = 20
            NumericUpDown1.Enabled = True
            SideXBox.Enabled = True
            Clear.Enabled = True
            SideXBox.Focus()
        ElseIf (AreaRadio.Checked And ComboBox1.SelectedItem = "AngleX") Then
            Clear.Enabled = True
            NumericUpDown1.Minimum = 0
            NumericUpDown1.Value = 0
            AnswerBox.Clear()
            NumericUpDown1.Enabled = False
            AreaBox.Enabled = True
            SideXBox.Enabled = True
            SideYBox.Enabled = True
            Button3.Enabled = True
            SideXBox.Focus()
        ElseIf (AreaRadio.Checked And ComboBox1.SelectedItem = "Area") Then
            AnswerBox.Clear()
            NumericUpDown1.Enabled = True
            AreaBox.Enabled = False
            SideXBox.Enabled = True
            SideYBox.Enabled = True
            Clear.Enabled = True
            SideXBox.Focus()
        ElseIf (SineRadio.Checked And ComboBox1.SelectedItem = "AngleX") Then
            ErrorProvider1.Clear()
            Form3.Show()
        ElseIf (SineRadio.Checked And ComboBox1.SelectedItem = "SideX") Then
            ErrorProvider1.Clear()
            Form3.Show()
        ElseIf (SineRadio.Checked And ComboBox1.SelectedItem = "SideY") Then
            ErrorProvider1.Clear()
            Form3.Show()
        ElseIf (SineRadio.Checked And ComboBox1.SelectedItem = "AngleY") Then
            ErrorProvider1.Clear()
            Form3.Show()
        ElseIf (CosineRadio.Checked And ComboBox1.SelectedItem = "SideX") Then
            ErrorProvider1.Clear()
            If (File.Exists("C:/Program Files/Trigsoft/Trigbase/Trigsoft.bat")) Then
                CONFIGCOS.Show()
            Else
                COSQ.Show()
            End If

        ElseIf (CosineRadio.Checked And ComboBox1.SelectedItem = "SideY") Then
            ErrorProvider1.Clear()
            If (File.Exists("C:/Program Files/Trigsoft")) Then
                CONFIGCOS.Show()
            Else
                COSQ.Show()
            End If
        ElseIf (CosineRadio.Checked And ComboBox1.SelectedItem = "SideZ") Then
            ErrorProvider1.Clear()
            If (File.Exists("C:/Program Files/Trigsoft")) Then
                CONFIGCOS.Show()
            Else
                COSQ.Show()
            End If

        ElseIf (CosineRadio.Checked And ComboBox1.SelectedItem = "AngleX") Then
            ErrorProvider1.Clear()
            If (File.Exists("C:/Program Files/Trigsoft")) Then
                CONFIGCOS.Show()
            Else
                COSQ.Show()
            End If
        ElseIf (ComboBox1.SelectedItem = Nothing) Then
            ErrorProvider1.SetError(ComboBox1, "Select a subject of formular in the box.")
        Else
            ErrorProvider1.Clear()
        End If
    End Sub

    Private Sub AngleBox_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs)
        If (ComboBox1.SelectedItem = "Area" And SideXBox.TextLength > 0 And SideYBox.TextLength > 0) Then
            AcceptButton = Me.Go
        End If
    End Sub

    Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Clear.Click

        If (MessageBox.Show("Are you sure you want to clear all?", "Notification", MessageBoxButtons.YesNo, MessageBoxIcon.Question) = Windows.Forms.DialogResult.Yes) Then
            AnswerBox.Clear()
            SideXBox.Clear()
            SideYBox.Clear()
            AreaBox.Clear()
            NumericUpDown1.Value = 20.0
            NumericUpDown2.Value = 20.0
        End If
    End Sub

    Private Sub ConfigureToolStripMenuItem1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
        Previews.Show()
    End Sub

    Private Sub PreviewsToolStripMenuItem1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PreviewsToolStripMenuItem1.Click
        Previews.Show()
    End Sub

    Private Sub TrigsoftToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TrigsoftToolStripMenuItem.Click
        TRIG.ShowDialog()
    End Sub

    Private Sub LinkLabel1_LinkClicked(ByVal sender As System.Object, ByVal e As System.Windows.Forms.LinkLabelLinkClickedEventArgs) Handles LinkLabel1.LinkClicked
        Helper.Show()
    End Sub

    Private Sub ExitToolStripMenuItem1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ExitToolStripMenuItem1.Click
        System.GC.Collect()
        Me.Refresh()
    End Sub

    Private Sub RestartToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RestartToolStripMenuItem.Click

        If (SideXBox.TextLength > 0 Or SideYBox.TextLength > 0) Then
            If (MessageBox.Show("Make sure that you are done with your current calculations.", "Notification", MessageBoxButtons.YesNo) = Windows.Forms.DialogResult.Yes) Then
                Application.Restart()
            End If
        Else
            Application.Restart()
        End If
    End Sub

    Private Sub ExitToolStripMenuItem2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ExitToolStripMenuItem2.Click
        Dim Path As String = "c:\Program Files\Trigsoft\Trigbase\Trigsoft"

        If (File.Exists(Path)) Then
            End
        ElseIf (Not File.Exists(Path)) Then
            SPECIALTHANKS.Show()
        End If
    End Sub

    Private Sub SideXBox_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SideXBox.TextChanged

        If (SideXBox.Text.Contains("a"c) Or SideXBox.Text.Contains("b"c) Or SideXBox.Text.Contains("c"c) Or SideXBox.Text.Contains("d"c) Or SideXBox.Text.Contains("e"c) Or SideXBox.Text.Contains("f"c) Or SideXBox.Text.Contains("g"c) Or SideXBox.Text.Contains("h"c) Or SideXBox.Text.Contains("i"c) Or SideXBox.Text.Contains("j"c) Or SideXBox.Text.Contains("k"c) Or SideXBox.Text.Contains("l"c) Or SideXBox.Text.Contains("m"c) Or SideXBox.Text.Contains("n"c) Or SideXBox.Text.Contains("o"c) Or SideXBox.Text.Contains("p"c) Or SideXBox.Text.Contains("q"c) Or SideXBox.Text.Contains("r"c) Or SideXBox.Text.Contains("s"c) Or SideXBox.Text.Contains("t"c) Or SideXBox.Text.Contains("u"c) Or SideXBox.Text.Contains("v"c) Or SideXBox.Text.Contains("w"c) Or SideXBox.Text.Contains("x"c) Or SideXBox.Text.Contains("y"c) Or SideXBox.Text.Contains("z"c)) Then
            Go.Enabled = False
            AreaBox.Enabled = False
            SideYBox.Enabled = False
            MessageBox.Show("Invalid input.", "Notification", MessageBoxButtons.OK, MessageBoxIcon.Error)
            Status.Text = "Invalid tokens. Use numeric values only."
        Else
            Status.Text = "Enter values"
            Go.Enabled = True
            AreaBox.Enabled = True
            SideYBox.Enabled = True
        End If
    End Sub

    Private Sub SideYBox_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SideYBox.TextChanged

        If (SideYBox.Text.Contains("a"c) Or SideYBox.Text.Contains("b"c) Or SideYBox.Text.Contains("c"c) Or SideYBox.Text.Contains("d"c) Or SideYBox.Text.Contains("e"c) Or SideYBox.Text.Contains("f"c) Or SideYBox.Text.Contains("g"c) Or SideYBox.Text.Contains("h"c) Or SideYBox.Text.Contains("i"c) Or SideYBox.Text.Contains("j"c) Or SideYBox.Text.Contains("k"c) Or SideYBox.Text.Contains("l"c) Or SideYBox.Text.Contains("m"c) Or SideYBox.Text.Contains("n"c) Or SideYBox.Text.Contains("o"c) Or SideYBox.Text.Contains("p"c) Or SideYBox.Text.Contains("q"c) Or SideYBox.Text.Contains("r"c) Or SideYBox.Text.Contains("s"c) Or SideYBox.Text.Contains("t"c) Or SideYBox.Text.Contains("u"c) Or SideYBox.Text.Contains("v"c) Or SideYBox.Text.Contains("w"c) Or SideYBox.Text.Contains("x"c) Or SideYBox.Text.Contains("y"c) Or SideYBox.Text.Contains("z"c)) Then
            Go.Enabled = False
            SideXBox.Enabled = False
            AreaBox.Enabled = False
            MessageBox.Show("Invalid input.", "Notification", MessageBoxButtons.OK, MessageBoxIcon.Error)
            Status.Text = "Invalid tokens. Enter numeric values only."
        Else
            Status.Text = "Enter values"
            Go.Enabled = True
            AreaBox.Enabled = True
            SideXBox.Enabled = True
        End If
    End Sub

    Private Sub AreaBox_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles AreaBox.TextChanged

        If (AreaBox.Text.Contains("a"c) Or AreaBox.Text.Contains("b"c) Or AreaBox.Text.Contains("c"c) Or AreaBox.Text.Contains("d"c) Or SideXBox.Text.Contains("e"c) Or AreaBox.Text.Contains("f"c) Or AreaBox.Text.Contains("g"c) Or AreaBox.Text.Contains("h"c) Or AreaBox.Text.Contains("i"c) Or AreaBox.Text.Contains("j"c) Or AreaBox.Text.Contains("k"c) Or AreaBox.Text.Contains("l"c) Or AreaBox.Text.Contains("m"c) Or AreaBox.Text.Contains("n"c) Or AreaBox.Text.Contains("o"c) Or AreaBox.Text.Contains("p"c) Or AreaBox.Text.Contains("q"c) Or AreaBox.Text.Contains("r"c) Or AreaBox.Text.Contains("s"c) Or AreaBox.Text.Contains("t"c) Or AreaBox.Text.Contains("u"c) Or AreaBox.Text.Contains("v"c) Or AreaBox.Text.Contains("w"c) Or AreaBox.Text.Contains("x"c) Or AreaBox.Text.Contains("y"c) Or AreaBox.Text.Contains("z"c)) Then
            Go.Enabled = False
            SideXBox.Enabled = False
            SideYBox.Enabled = False
            MessageBox.Show("Invalid input.", "Notification", MessageBoxButtons.OK, MessageBoxIcon.Error)
            Status.Text = "Invalid tokens. Enter numeric values only."
        Else
            Status.Text = "Enter values"
            Go.Enabled = True
            SideXBox.Enabled = True
            SideYBox.Enabled = True

        End If
    End Sub

    Private Sub AnswerBox_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles AnswerBox.TextChanged
        If (AnswerBox.TextLength > 0) Then
            Status.Text = "Ready"
        End If

        Math.Round(Ans, CInt(Fixer.Value))
    End Sub

    Private Sub TrigsoftToolStripMenuItem2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TrigsoftToolStripMenuItem2.Click
        TRIGSOFTCONFI.ShowDialog()
    End Sub

    Private Sub TrigcalcToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TrigcalcToolStripMenuItem.Click
        Trigcalc.Show()
    End Sub

    Private Sub NotepadToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles NotepadToolStripMenuItem.Click
        Process.Start("notepad.exe")
    End Sub

    Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
        Trigcalc.Hide()
    End Sub

    ' Implementation of Trigcalc starts ------------------------------------------------------------------------------------------------------------------------------------------------
    ' Main class of Trigcalc

    ' Diclare public variables
    Dim Numerator = 0
    Dim Answer As Integer = 0

    'Diclare logic chechUps

    Dim MinusClick As Boolean = False
    Dim PlusClick As Boolean = False
    Dim DivClick As Boolean = False
    Dim MultClick As Boolean = False

    Private Sub One_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles One.Click
        Display.Text += One.Text
    End Sub

    Private Sub Two_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Two.Click
        Display.Text += Two.Text
    End Sub

    Private Sub Three_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Three.Click
        Display.Text += Three.Text
    End Sub

    Private Sub Four_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Four.Click
        Display.Text += Four.Text
    End Sub

    Private Sub Five_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Five.Click
        Display.Text += Five.Text
    End Sub

    Private Sub Six_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Six.Click
        Display.Text += Six.Text
    End Sub

    Private Sub Seven_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Seven.Click
        Display.Text += Seven.Text
    End Sub

    Private Sub Eight_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Eight.Click
        Display.Text += Eight.Text
    End Sub

    Private Sub Nine_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Nine.Click
        Display.Text += Eight.Text
    End Sub

    Private Sub Dot_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Dot.Click
        Display.Text += Dot.Text
    End Sub

    Private Sub Zero_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Zero.Click
        Display.Text += Zero.Text
    End Sub

    Private Sub Equals_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Equals.Click

    End Sub

    Private Sub Sin_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Sin.Click

    End Sub

    Private Sub Cos_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Cos.Click

    End Sub

    Private Sub Tan_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Tan.Click

    End Sub

    Private Sub Button1_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Display.Clear()
    End Sub

    Private Sub InverseTick_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles InverseTick.CheckedChanged

    End Sub

    Private Sub Button6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnMinus.Click

    End Sub

    Private Sub btnMult_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnMult.Click
        Numerator = Double.Parse(Display.Text)
        CStore.Text = (Numerator & btnMult.Text)
    End Sub
End Class 'Main
